package gjtx4;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class Difference1 {
    public static void main(String[] args) {
        Map<String,String> m=new TreeMap<>();
        Map<String,String> m1=new HashMap<>();
        long b=System.nanoTime();
        for (int i=0;i<100000;i++){
            m.put("a"+i,i+"");
        }
        long c=System.nanoTime()-b;
        for (int i=1;i<=100;i++){
            m.remove("a"+((int)Math.random()*m.size()));
        }
        long d=System.nanoTime()-c-b;

        long b1=System.nanoTime();
        for (int i=1;i<100000;i++){
            m1.put("a"+i,i+"");
        }
        long c1=System.nanoTime()-b1;
        for (int i=1;i<=100;i++){
            m1.remove("a"+((int)Math.random()*m.size()));
        }
        long d1=System.nanoTime()-c1-b1 ;

        System.out.println("加入时间比较：");
        if (c>c1){
            System.out.println("HashMap快！！");
        }else {
            System.out.println("TreeMap快");
        }
        System.out.println("删除时间比较：");
        if (d>d1){
            System.out.println("HashMap快！！");
        }else {
            System.out.println("TreeMap快");
        }

    }
}
